package com.smart.manager.product.controller;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.smart.common.entities.ajax.AjaxResult;
import com.smart.common.entities.constant.SmartConstant;
import com.smart.common.entities.core.Page;
import com.smart.common.entities.domain.TaskResult;
import com.smart.manager.product.entities.body.RBasicCamera;
import com.smart.manager.product.entities.models.BasicCamera;
import com.smart.manager.product.repository.BasicCameraRepository;
import com.smart.service.remind.RemindService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;


/**
 * 监控资料
 * @author leo
 * @date 2023/09/13
 */
@Api(tags =  "监控资料")
@RestController
@RequestMapping(SmartConstant.MANAGER_API_PREFIX + "product/basic/camera")
@RequiredArgsConstructor
public class BasicCameraApi {

    private final BasicCameraRepository repository;
    private final RemindService remindService;

    @GetMapping(value = "pageList")
    @ApiOperation(value = "查询监控")
    @SaCheckPermission("product:camera:pageList")
    public AjaxResult<Page<BasicCamera>> pageList(@Validated RBasicCamera.SearchBody body) {
        Page<BasicCamera> result = repository.pageList(body);
        return AjaxResult.data(result);
    }

    @ApiOperation(value = "修改监控")
    @PutMapping("update/{id}")
    @SaCheckPermission("product:camera:update")
    public AjaxResult<String> update(@PathVariable Long id, @RequestBody @Validated RBasicCamera.EditBody data) {
        repository.update( id, data );
        return AjaxResult.success();
    }
    @ApiOperation(value = "获取直播地址")
    @GetMapping("getAddress")
    @SaCheckPermission("product:camera:getAddress")
    public AjaxResult<String> address(@Validated Long id) {
        String address = repository.getAddress(id,true);
        return AjaxResult.data(address);
    }

    @ApiOperation(value = "刷新监控")
    @GetMapping("refreshCamera")
    @SaCheckPermission("product:camera:refreshCamera")
    public AjaxResult<TaskResult> refreshCamera() {
        TaskResult result = repository.refreshCamera();
        return AjaxResult.data(result);
    }


}
